package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.AgencyInfo;
import cn.wolfcode.crm.query.AgencyInfoQueryObject;
import cn.wolfcode.crm.service.IAgencyInfoService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("agencyInfo")
public class AgencyInfoController {

    @Autowired
    IAgencyInfoService agencyInfoService;
    @RequestMapping("")
    public String index() {
        return "agencyInfo/list";
    }


    @RequestMapping("list")
    @ResponseBody
    @RequiresPermissions("agencyInfo:list")
    @PermissionName("机构列表")
    public PageResult list(AgencyInfoQueryObject qo) {
        return agencyInfoService.query(qo);
    }

    //===============查询所有机构,后面分组查询用到==================
    @RequestMapping("queryAgencies")
    @ResponseBody
    public List<AgencyInfo> queryAgencies() {
        return agencyInfoService.selectAll();
    }


    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(AgencyInfo record) {
        JsonResult result = new JsonResult();
        try {
            agencyInfoService.insert(record);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg("保存操作失败");
        }
        return result;
    }
    @RequestMapping("update")
    @ResponseBody
    @RequiresPermissions("agencyInfo:update")
    @PermissionName("机构更新")
    public JsonResult update(AgencyInfo record) {
        JsonResult result = new JsonResult();
        try {
            agencyInfoService.updateByPrimaryKey(record);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg("更新操作操作失败");
        }
        return result;
    }
    @RequestMapping("changeSate")
    @ResponseBody
    @RequiresPermissions("agencyInfo:changeSate")
    @PermissionName("机构状态修改")
    public JsonResult changeSate(Long id) {
        JsonResult result = new JsonResult();
        try {
            agencyInfoService.changeSate(id);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg("更新操作操作失败");
        }
        return result;
    }
    @RequestMapping("queryAgency")
    @ResponseBody
    @RequiresPermissions("agencyInfo:queryAgency")
    @PermissionName("查询机构数据")
    public List<AgencyInfo> queryAgency() {

        return agencyInfoService.queryAll();
    }

}
